package com.tzbank.back.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tzbank.back.dao.RoleMapper;
import com.tzbank.back.service.RoleService;
import com.tzbank.entity.backstage.Role;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

@Service
public class RoleServiceImpl implements RoleService {

	@Autowired
	private RoleMapper roleMapper;

	@Transactional
	@Override
	public Map<String, Object> deleteRole(Role role) throws Exception{
		this.roleMapper.deleteRole(role);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> insertRole(Role role) throws Exception{
		this.roleMapper.insertRole(role);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> selectRoleByAutoId(int autoId) throws Exception{
		Role role = this.roleMapper.selectRoleByAutoId(autoId);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), role);
	}

	@Override
	public Map<String, Object> selectRoleList() throws Exception{
		List<Role> roles = this.roleMapper.selectRoleList();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), roles);
	}

	@Transactional
	@Override
	public Map<String, Object> updateRole(Role role) throws Exception{
		this.roleMapper.updateRole(role);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
